/**
 * 程序的入口, 类似java中的main
 */

import React from 'react';
import ReactDOM from 'react-dom';
import {Route, HashRouter, Control} from 'react-keeper';

import './statics/iconfont/iconfont.css'; // 引入字体库样式

// 引入自定义组件
import Home from 'Pages/Home';
import GoodsDetail from 'Pages/GoodsDetail';
import CategoryGoodsList from 'Pages/CategoryGoodsList';
import UserInfo from 'Pages/UserInfo';
import Login from 'Pages/Login';
import Register from 'Pages/Register';
import SelectAddress from 'Pages/SelectAddress';
import AddAddress from 'Pages/AddAddress';


// 定义过滤器
const loginFilter = (callback, props) => {
  Control.go('/user/login');
};

// react-router-dom 4^ 去除了路由嵌套，使用 react-keeper 来拆分路由
const Goods = () => {
  return (
    <div>
      <Route exact path='/detail/:id' component={GoodsDetail}/>
      <Route exact path='/category/:id' component={CategoryGoodsList}/>

    </div>
  );
};
const User = () => {
  return (
    <div>
      <Route exact path='/login' component={Login}/>
      <Route exact path='/register' component={Register}/>
      <Route exact path='/info' component={UserInfo} enterFilter={loginFilter}/>
    </div>
  );
};
const Address = () => {
  return (
    <div>
      <Route exact path='/select' component={SelectAddress}/>
      <Route exact path='/add' component={AddAddress}/>
    </div>
  );
};

const routes = (
  <HashRouter>
    <div>
      {/*首页*/}
      <Route LinkCache exact path='/' component={Home}/>
      {/*商品相关路由*/}
      <Route exact path='/goods' component={Goods}/>
      {/*用户相关路由*/}
      <Route exact path='/user' component={User}/>
      {/*收货地址相关路由*/}
      <Route exact path='/address' component={Address}/>
    </div>
  </HashRouter>
);

ReactDOM.render(routes, document.getElementById('root'));
